package util;

import org.junit.jupiter.api.Test;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

public class MxQueue {

    @Test
    public void testQueue() {
        Queue<Integer> queue = new ConcurrentLinkedQueue<>();
        queue.add(1);
        queue.add(2);
        queue.add(3);
        queue.add(4);
        queue.poll();
        queue.add(1);
        for (Integer integer : queue) {
            System.out.println(integer);
        }
    }

    public static void main(String[] args) {
        LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();

        AtomicInteger i = new AtomicInteger();

        new Thread(() -> {
            while (true) {
                int num = i.getAndIncrement();
                queue.add(num);
                System.out.println("add: " + num);
            }
        }).start();

        new Thread(() -> {
            while (true) {
                System.out.println("poll: " + queue.poll());
            }
        }).start();
    }
}
